package wifiunion.com.notice.presenter;

import android.content.Context;


import java.util.HashMap;

import wifiunion.com.notice.BaseView;
import wifiunion.com.notice.Constants;


/**
 * Created by Administrator on 2016/10/14.
 */
public class LoginPresenter implements LoginDetailContact.Presenter, LoginDetailContact.Callback {

    private BaseView mView;
    private Context mContext;
    private LoginModel mLoginModel;

    /**
     * 0 cloud登录 1获取验证码 2系统登录
     * <p>
     * 4 服务版本  5 app版本
     * <p>
     * 6 获取子场景 权限
     */

    private int mType;

    public LoginPresenter(Context context, BaseView view, int type) {
        mView = view;
        mContext = context;
        mLoginModel = new LoginModel();
        mType = type;
        mView.setPresenter(this);
    }

    @Override
    public void start() {


    }

    @Override
    public void start(HashMap<String, Object> params) {
        mLoginModel.loadData(Constants.HTTP_URL_GET_LOGIN, params, this);
    }


    public void startFilter(HashMap<String, Object> params) {
        mLoginModel.loadData(Constants.HTTP_URL_GET_LOGIN, params, this);
    }



    @Override
    public void onSuccess(Object data) {

        switch (mType) {
            case 0:
            case 2:
                ((LoginDetailContact.View) mView).showSuccess(data);
                break;
            case 1:
                ((LoginDetailContact.RegisterView) mView).sendValidSuccess();
                break;
            case 3:
                ((LoginDetailContact.RegisterView) mView).registerSuccess(data);
                break;

            case 4:

                ((LoginDetailContact.VersionView) mView).onGetServerVersionSuccess(data);
                break;
            case 5:
                ((LoginDetailContact.VersionView) mView).onGetAppVersionSuccess(data);
                break;
            case 6:
                ((LoginDetailContact.LoginSubPlaceView) mView).loginSubPlaceSuccess(data);
                break;

        }


//        mView.showSuccess(data);
    }

    @Override
    public void onServerFailed(Object errorObj) {
        switch (mType) {
            case 0:
            case 2:
                ((LoginDetailContact.View) mView).showError(errorObj);
                break;
            case 1:
                ((LoginDetailContact.RegisterView) mView).sendValidFailed(errorObj);
                break;
            case 3:
                ((LoginDetailContact.RegisterView) mView).registerFailed(errorObj);
                break;
            case 4:

                ((LoginDetailContact.VersionView) mView).onGetServerVersionFailed(errorObj);
                break;
            case 5:
                ((LoginDetailContact.VersionView) mView).onGetAppVersionFailed(errorObj);
                break;
            case 6:
                ((LoginDetailContact.LoginSubPlaceView) mView).loginSubPlaceFailed(errorObj);

                break;
        }

//        mView.showError(errorObj);
    }

    @Override
    public void onNetFailed() {
        switch (mType) {
            case 0:
            case 2:
                ((LoginDetailContact.View) mView).showError("网络异常，请稍后再试");
                break;
            case 1:
                ((LoginDetailContact.RegisterView) mView).sendValidFailed("网络异常，请稍后再试");
                break;
            case 3:
                ((LoginDetailContact.RegisterView) mView).registerFailed("网络异常，请稍后再试");
                break;
            case 4:

                ((LoginDetailContact.VersionView) mView).onGetServerVersionFailed("网络异常，请稍后再试");
                break;
            case 5:
                ((LoginDetailContact.VersionView) mView).onGetAppVersionFailed("网络异常，请稍后再试");
                break;
            case 6:
                ((LoginDetailContact.LoginSubPlaceView) mView).loginSubPlaceFailed("网络异常，请稍后再试");
                break;

        }


//        mView.showError("网络异常，请稍后再试");
    }

    /**
     * 获取验证码
     *
     * @param params
     */
    public void getValidCodeRequest(HashMap<String, Object> params) {
        mLoginModel.getVerCode(params, this);
    }

    /**
     * 登录云服务
     *
     * @param params
     */
    public void loginICloud(HashMap<String, Object> params) {
        mLoginModel.loginIcloud(params, this);
    }


    /**
     * 注册云服务
     *
     * @param params
     */
    public void regICloud(HashMap<String, Object> params) {
        mLoginModel.regIcloud(params, this);
    }







    public void loginSubPlace(HashMap<String, Object> params) {
        mLoginModel.loginSubPlaceRequest(params,this);
    }




}
